package com.sxfq.loansupermarket.backsystem.modular.remoteSynergy.controller;

import com.sxfq.loansupermarket.backsystem.common.constant.Const;
import com.sxfq.loansupermarket.backsystem.common.constant.state.ManagerStatus;
import com.sxfq.loansupermarket.backsystem.common.controller.BaseController;
import com.sxfq.loansupermarket.backsystem.common.exception.BizExceptionEnum;
import com.sxfq.loansupermarket.backsystem.common.exception.BussinessException;
import com.sxfq.loansupermarket.backsystem.common.persistence.dao.UserMapper;
import com.sxfq.loansupermarket.backsystem.common.persistence.model.User;
import com.sxfq.loansupermarket.backsystem.core.log.LogManager;
import com.sxfq.loansupermarket.backsystem.core.log.factory.LogTaskFactory;
import com.sxfq.loansupermarket.backsystem.core.shiro.ShiroKit;
import com.sxfq.loansupermarket.backsystem.core.shiro.ShiroUser;
import com.sxfq.loansupermarket.backsystem.core.support.DateTimeKit;
import com.sxfq.loansupermarket.backsystem.core.support.HttpKit;
import com.sxfq.loansupermarket.backsystem.modular.base.SqlMapper;
import com.sxfq.loansupermarket.backsystem.modular.remoteSynergy.entity.*;
import com.sxfq.loansupermarket.backsystem.modular.system.dao.UserMgrDao;
import com.sxfq.loansupermarket.backsystem.modular.system.factory.UserFactory;
import com.sxfq.loansupermarket.backsystem.modular.system.transfer.UserDto;
import org.apache.commons.io.FileUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import com.sxfq.loansupermarket.backsystem.modular.remoteSynergy.service.ICaseSelectionService;
import com.sxfq.loansupermarket.backsystem.modular.remoteSynergy.service.ICaseSelectionUploadService;
import com.sxfq.loansupermarket.backsystem.modular.remoteSynergy.service.ICaseSelectionManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Base64;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
 * @author py
 * @Date
 */
@Controller
@RequestMapping("/caseSelectionVote")
public class CaseSelectionVoteController extends BaseController {
    @Autowired
    ICaseSelectionUploadService CaseSelectionUploadService;

    @Autowired
    ICaseSelectionService caseSelectionService;

    @Autowired
    private SqlMapper sqlMapper;

    @Resource
    private UserMapper userMapper;

    @Resource
    private UserMgrDao managerDao;

    @Autowired
    ICaseSelectionManagementService managementService;

    private String PREFIX = "/remoteSynergy/weixin/";

    private String PREFIY = "/remoteSynergy/";

    static String phoneReg = "\\b(ip(hone|od)|android|opera m(ob|in)i" + "|windows (phone|ce)|blackberry" + "|s(ymbian|eries60|amsung)|p(laybook|alm|rofile/midp"
            + "|laystation portable)|nokia|fennec|htc[-_]" + "|mobile|up.browser|[1-4][0-9]{2}x[1-4][0-9]{2})\\b";
    static String tableReg = "\\b(ipad|tablet|(Nexus 7)|up.browser" + "|[1-4][0-9]{2}x[1-4][0-9]{2})\\b";

    // 移动设备正则匹配：手机端、平板
    static Pattern phonePat = Pattern.compile(phoneReg, Pattern.CASE_INSENSITIVE);
    static Pattern tablePat = Pattern.compile(tableReg, Pattern.CASE_INSENSITIVE);

    /**
     * 检测是否是移动设备访问
     *
     * @Title: check
     * @Date : 2014-7-7 下午01:29:07
     * @param userAgent
     *            浏览器标识
     * @return true:移动设备接入，false:pc端接入
     */
    protected boolean check(String userAgent) {
        if (null == userAgent) {
            userAgent = "";
        }
        // 匹配
        Matcher matcherPhone = phonePat.matcher(userAgent);
        Matcher matcherTable = tablePat.matcher(userAgent);
        if (matcherPhone.find() || matcherTable.find()) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 获取设备名称
     * @param userAgent
     * @return
     */
    public String getDeviceName(String userAgent) throws Exception{
        if (null == userAgent) {
            userAgent = "";
        }
        // 匹配
        Matcher matcherPhone = phonePat.matcher(userAgent);
        Matcher matcherTable = tablePat.matcher(userAgent);
        if (matcherPhone.find()) {
            return matcherPhone.group();
        } else if (matcherTable.find()) {
            return matcherTable.group();
        } else {
            return "pc";
        }
    }

    /**
     * 跳转到病例评选管理页面
     */
    @RequestMapping("")
    public String to_caseSelection(Model model) {
        String getCount = "select (select count(id) from case_selection_information) as caseCount," +
                "(select sum(votes) from case_selection_information)  as totaVotes from dual";
        TongJiInfo info = sqlMapper.selectOne(getCount, TongJiInfo.class);
        model.addAttribute("countInfo", info);
        return PREFIX + "/case_selection_vote.html";
    }

    /**
     * 跳转到病例评选管理页面 注册
     */
    @RequestMapping("/index")
    public String to_caseSelectionLogin(Model model) {
        String getCount = "select (select count(id) from case_selection_information) as caseCount," +
                "(select sum(votes) from case_selection_information)  as totaVotes from dual";
        TongJiInfo info = sqlMapper.selectOne(getCount, TongJiInfo.class);
        model.addAttribute("countInfo", info);
        return PREFIX + "/case_selection_vote_index.html";
    }


    @RequestMapping(value = "/getCaseList", method = RequestMethod.POST)
    @ResponseBody
    public List<CaseSelectionUploadInfo> report(int numberBars, int page) {
        return CaseSelectionUploadService.getCaseList(numberBars, page);
    }

    /**
     * 点击查看该医院所有病例
     */
    @RequestMapping("/scoreViewCases/{obj}")
    public String scoreViewCases(@PathVariable String obj, Model model) {
        List<CaseSelectionUploadInfo> caseOfOutpatientList = caseSelectionService.getCaseOfOutpatientList(obj);
        model.addAttribute("caseOfOutpatientList", caseOfOutpatientList);
        model.addAttribute("fullName", obj);
        return PREFIX + "/case_scoreViewCases.html";
    }

    /**
     * 点击查看医院提交病例详情
     */
    @RequestMapping("/caseScoring/{fullObj}")
    public String caseScoring(@PathVariable String fullObj, Model model) {
        String fullName = fullObj.split(",")[0];
        String obj = fullObj.split(",")[1];
        model.addAttribute("fullName", fullName);
        model.addAttribute("id", obj);
        return PREFIX + "/case_caseScoring.html";
    }

    /**
     * 点击查看患者信息
     */
    @RequestMapping("/patientInformation/{fullObj}")
    public String patientInformation(@PathVariable String fullObj, Model model) {
        String fullName = fullObj.split(",")[0];
        String obj = fullObj.split(",")[1];
        CaseSelectionUploadInfo caseSelectionInfo = caseSelectionService.getCaseOfId(obj);
        model.addAttribute("caseSelectionInfo", caseSelectionInfo);
        model.addAttribute("fullName", fullName);
        return PREFIX + "/case_patientInformation.html";
    }

    /**
     * 通过病历id或者医生名称查询病历
     */
    @RequestMapping("/searchCases/{obj}")
    public String searchCases(@PathVariable String obj, Model model) {
        List<CaseSelectionUploadInfo> caseOfOutpatientList = caseSelectionService.getCaseByIdOrName(obj);
        model.addAttribute("caseOfOutpatientList", caseOfOutpatientList);
        model.addAttribute("fullName", obj);
        return PREFIX + "/case_scoreViewCases.html";
    }

    /**
     * 点击查看临床病例
     */
    @RequestMapping("/clinicalCase/{fullObj}")
    public String clinicalCase(@PathVariable String fullObj, Model model) {
        String fullName = fullObj.split(",")[0];
        String obj = fullObj.split(",")[1];
        CaseSelectionUploadInfo caseSelectionInfo = caseSelectionService.getCaseOfId(obj);
        model.addAttribute("caseSelectionInfo", caseSelectionInfo);
        model.addAttribute("fullName", fullName);
        return PREFIX + "/case_clinicalCase.html";
    }

    /**
     * 点击查看辅助检查
     */
    @RequestMapping("/supplementary/{fullObj}")
    public String supplementary(@PathVariable String fullObj, Model model) {
        String fullName = fullObj.split(",")[0];
        String obj = fullObj.split(",")[1];
        CaseSelectionUploadInfo caseSelectionInfo = caseSelectionService.getCaseOfId(obj);
        model.addAttribute("caseSelectionInfo", caseSelectionInfo);
        model.addAttribute("fullName", fullName);
        return PREFIX + "/case_supplementary.html";
    }

    /**
     * 点击查看治疗计划
     */
    @RequestMapping("/treatmentDesign/{fullObj}")
    public String treatmentDesign(@PathVariable String fullObj, Model model) {
        String fullName = fullObj.split(",")[0];
        String obj = fullObj.split(",")[1];
        CaseSelectionUploadInfo caseSelectionInfo = caseSelectionService.getCaseOfId(obj);
        model.addAttribute("caseSelectionInfo", caseSelectionInfo);
        model.addAttribute("fullName", fullName);
        return PREFIX + "/case_treatmentDesign.html";
    }

    /**
     * 点击查看治疗步骤
     */
    @RequestMapping("/treatmentStepsDetails/{fullObj}")
    public String treatmentStepsDetails(@PathVariable String fullObj, Model model) {
        String fullName = fullObj.split(",")[0];
        String obj = fullObj.split(",")[1];
        CaseSelectionUploadInfo caseSelectionInfo = caseSelectionService.getCaseOfId(obj);
        model.addAttribute("caseSelectionInfo", caseSelectionInfo);
        model.addAttribute("fullName", fullName);
        return PREFIX + "/case_treatmentStepsDetails.html";
    }

    /**
     * 点击查看治疗步骤
     */
    @RequestMapping("/postoperative/{fullObj}")
    public String postoperative(@PathVariable String fullObj, Model model) {
        String fullName = fullObj.split(",")[0];
        String obj = fullObj.split(",")[1];
        CaseSelectionUploadInfo caseSelectionInfo = caseSelectionService.getCaseOfId(obj);
        model.addAttribute("caseSelectionInfo", caseSelectionInfo);
        model.addAttribute("fullName", fullName);
        return PREFIX + "/case_postoperative.html";
    }

    /**
     * 跳转到规则详情
     */
    @RequestMapping("/ruleDetails")
    public String ruleDetails(Model model) {
        return PREFIX + "/case_ruleDetails.html";
    }

    /**
     * 跳转到排名统计
     */
    @RequestMapping("/rankingStatistics")
    public String rankingStatistics(Model model) {
        String sql = "select t.id as id,t.creater as creater,t.case_score as caseScore," +
                "(select count(s.case_score)+1 from case_selection_information s where s.case_score>t.case_score) as scoreRanking " +
                "from case_selection_information t " +
                "order by (select count(s.case_score)+1 from case_selection_information s where s.case_score>t.case_score) LIMIT 3,17";
        List<CaseSelectionVotesInfo> list = sqlMapper.selectList(sql, CaseSelectionVotesInfo.class);
        model.addAttribute("rankingList", list);
        String sql3 = "select t.id as id,t.creater as creater,t.case_score as caseScore," +
                "(select count(s.case_score)+1 from case_selection_information s where s.case_score>t.case_score) as scoreRanking " +
                "from case_selection_information t " +
                "order by (select count(s.case_score)+1 from case_selection_information s where s.case_score>t.case_score) LIMIT 3";
        List<CaseSelectionVotesInfo> list3 = sqlMapper.selectList(sql3, CaseSelectionVotesInfo.class);
        model.addAttribute("rankingList3", list3);
        return PREFIX + "/case_rankingStatistics.html";
    }

    /**
     * 跳转到选手搜索
     */
    @RequestMapping("/searchPlayer")
    public String searchPlayer(Model model) {
        return PREFIX + "/case_searchPlayer.html";
    }

    /**
     * 跳转到规则详情
     */
    @RequestMapping("/caseUploadRegister")
    public String caseUploadRegister(Model model) {
        return PREFIX + "/case_uploadRegister.html";
    }

    /**
     * 跳转到我的
     */
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String case_myRankingStatistics(Model model) {
        ShiroUser shiroUser = ShiroKit.getUser();
        if (shiroUser == null) {
            return PREFIX + "/case_playerLoginPage.html";
        } else {
            String sql = "select * from user where id='" + shiroUser.getId() + "'";
            User userInfo = sqlMapper.selectOne(sql, User.class);
            model.addAttribute("userInfo", userInfo);
            model.addAttribute("outpatientName", ShiroKit.getSessionAttr("outpatientName"));
            model.addAttribute("username", ShiroKit.getSessionAttr("username"));
            model.addAttribute("password", ShiroKit.getSessionAttr("password"));
            model.addAttribute("avatar", userInfo.getAvatar());
            return PREFIX + "/case_myRankingStatistics.html";
        }
    }

    /**
     * 跳转到主页
     */
    @RequestMapping(value = "/myRankingStatistics", method = RequestMethod.GET)
    public String to_index(Model model) {
        ShiroUser shiroUser = ShiroKit.getUser();
        if (shiroUser == null) {
            return PREFIX + "/case_playerLoginPage.html";
        } else {
            String sql = "select * from user where id='" + shiroUser.getId() + "'";
            User userInfo = sqlMapper.selectOne(sql, User.class);
            if(userInfo==null){
                return PREFIX + "/case_playerLoginPage.html";
            } else {
                model.addAttribute("userInfo", userInfo);
                model.addAttribute("outpatientName", ShiroKit.getSessionAttr("outpatientName"));
                model.addAttribute("username", ShiroKit.getSessionAttr("username"));
                model.addAttribute("password", ShiroKit.getSessionAttr("password"));
                model.addAttribute("avatar", userInfo.getAvatar());
                return PREFIX + "/case_myRankingStatistics.html";
            }
        }
    }

    /**
     * 跳转到个人中心
     */
    @RequestMapping("/personalCenter")
    public String case_personalCenter(Model model) {
        ShiroUser shiroUser = ShiroKit.getUser();
        if (shiroUser == null) {
            return PREFIX + "/case_playerLoginPage.html";
        }
        String sql = "select * from user where id='" + shiroUser.getId() + "'";
        User user = sqlMapper.selectOne(sql, User.class);
        model.addAttribute("user", user);
        return PREFIX + "/case_personalCenter.html";
    }

    /**
     * 跳转到个人中心修改资料
     */
    @RequestMapping("/case_personalMaterial")
    public String case_personalMaterial(Model model) {
        ShiroUser shiroUser = ShiroKit.getUser();
        if (shiroUser == null) {
            return PREFIX + "/case_playerLoginPage.html";
        }
        String sql = "select * from user where id='" + shiroUser.getId() + "'";
        User user = sqlMapper.selectOne(sql, User.class);
        model.addAttribute("user", user);
        return PREFIX + "/update_personalMaterial.html";
    }

    /**
     * 跳转到个人中心修改密码
     */
    @RequestMapping("/case_personalPassword")
    public String case_personalPassword(Model model) {
        ShiroUser shiroUser = ShiroKit.getUser();
        if (shiroUser == null) {
            return PREFIX + "/case_playerLoginPage.html";
        }
        String sql = "select * from user where id='" + shiroUser.getId() + "'";
        User user = sqlMapper.selectOne(sql, User.class);
        model.addAttribute("user", user);
        return PREFIX + "/update_personalPassword.html";
    }


    @RequestMapping("/to_caseQRCode")
    public String to_caseQRCode(Model model) {
        model.addAttribute("imgName", "http://www.yiyatest.cn:8070/wdyltblpx_tpimg.png");
        return PREFIY + "/caseQRCode.html";
    }

    /**
     * 跳转到选手注册
     */
    @RequestMapping("/registerPlayer")
    public String registerPlayer(Model model) {
        String randomNumbersql = "select DATE_FORMAT(now(),'%Y%m%d%k%i%S') as randomNumber from dual";
        DaulInfo infos = sqlMapper.selectOne(randomNumbersql, DaulInfo.class);
        model.addAttribute("num", infos.getRandomNumber());
        return PREFIX + "/case_registerPlayer.html";
    }

    /**
     * 修改保存
     */
    @RequestMapping(value = "/registerPlayerUp", method = RequestMethod.POST)
    @ResponseBody
    public void registerPlayerUp(UserDto user, BindingResult result) {
        if (result.hasErrors()) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        if (ShiroKit.hasRole(Const.ADMIN_NAME)) {
            user.setDeptid(user.getDeptid() + ",");
            this.userMapper.updateById(UserFactory.createUser(user));
        } else {
            ShiroUser shiroUser = ShiroKit.getUser();
            if (shiroUser.getId().equals(user.getId())) {
                this.userMapper.updateById(UserFactory.createUser(user));
            } else {
                throw new BussinessException(BizExceptionEnum.NO_PERMITION);
            }
        }
    }

    /**
     * 注册保存
     */
    @RequestMapping(value = "/registerPlayerOk", method = RequestMethod.POST)
    @ResponseBody
    public int registerPlayerOk(UserDto user) {
        String base64Data = user.getAvatar().split(",")[1];
        Base64.Decoder decoder = Base64.getDecoder();
        byte[] bytes = decoder.decode(base64Data);
        FileOutputStream fos = null;
        try {
            String sql="select id from user where account='"+user.getAccount().split(",")[0]+"'";
            TongJiInfo tongJiInfo =sqlMapper.selectOne(sql,TongJiInfo.class);
            if(tongJiInfo!=null){
                return 2;
            }
            /* 找出指定的2个字符在 该字符串里面的 位置 */
            int strStartIndex = user.getAvatar().indexOf("/") + 1;
            int strEndIndex = user.getAvatar().indexOf(";");
                /* 开始截取 */
            String hz = user.getAvatar().substring(strStartIndex, strEndIndex);
            String iconName = bytes.toString() + "." + hz;
            fos = new FileOutputStream("D:\\201903071\\apache-tomcat-8.0.30\\webapps\\ROOT\\yingxiang\\" + iconName + "");
            fos.write(bytes);  //写入文件
            String httpUrl = "http://47.98.150.186:8070/yingxiang/" + iconName;
            user.setAccount(user.getPhone());
            user.setRoleid("84");
            user.setDeptid("24,");
            user.setAvatar(httpUrl);
            user.setSalt(ShiroKit.getRandomSalt(5));
            // 判断账号是否重复
            User theUser = managerDao.getByAccount(user.getAccount().split(",")[0]);
            if (theUser != null) {
                return 0;
            }
            user.setPassword(ShiroKit.md5(user.getPassword().split(",")[0], user.getSalt()));
            user.setStatus(ManagerStatus.OK.getCode());
            user.setCreatetime(new Date());
            this.userMapper.insert(UserFactory.createUser(user));
        } catch (IOException e) {
            e.printStackTrace();
            return 0;
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                    return 0;
                }
            }
        }
        return 1;
    }

    /**
     * 上传图片(上传到项目的webapp/static/img)
     */
    @RequestMapping(method = RequestMethod.POST, path = "/upLoadProcess/{cri}")
    @ResponseBody
    public String upLoadProcess(@RequestPart("file") MultipartFile picture,
                                @PathVariable String cri) {
        String num = cri.split(",")[2];
        String realPath = "D:\\201903071\\apache-tomcat-8.0.30\\webapps\\ROOT\\yingxiang";
        String httpUrl = "http://47.98.150.186:8070/yingxiang/";
        String imageurl = httpUrl + "\\" + picture.getOriginalFilename();
        try {
            FileUtils.copyInputStreamToFile(picture.getInputStream(), new File(realPath, picture.getOriginalFilename()));
            String deletesql="delete from case_zx_tx_info where num='"+num+"'";
            sqlMapper.delete(deletesql);
            String sql = "INSERT INTO `case_zx_tx_info` (`image_url`, `num`) VALUES\n" +
                    "( '" + imageurl + "', '" + num + "');";
            sqlMapper.insert(sql);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return imageurl;
    }

    //获取 图片
    @RequestMapping(value = "/getImg", method = RequestMethod.POST)
    @ResponseBody
    public IconInfo getImg(String num, String typeIcon, String informationId) throws Exception {
        String sql = "select * from case_zx_tx_info where num='" + num + "' limit 1";
        IconInfo iconInfo = sqlMapper.selectOne(sql, IconInfo.class);
        return iconInfo;
    }

    /**
     * 跳转到选手详情
     */
    @RequestMapping("/enterDetails/{obj}")
    public String enterDetails(@PathVariable String obj,HttpServletRequest request, Model model)throws Exception{
        CaseSelectionUploadInfo caseSelectionInfo = caseSelectionService.getCaseOfIdOrName(obj);
        String ua = request.getHeader("User-Agent").toLowerCase();
        try {
            String sql="select id from case_wechat_vote where createtime=left(now(),10) and unique_identification='"+ua+"' ";
            String sql1="select id from case_wechat_vote where createtime=left(now(),10) and unique_identification='"+ua+"' and caseid="+caseSelectionInfo.getId()+" limit 1";
            List<TongJiInfo> TongJiInfoList=sqlMapper.selectList(sql,TongJiInfo.class);
            TongJiInfo TongJiInfo=sqlMapper.selectOne(sql1,TongJiInfo.class);
            if(TongJiInfoList.size()>=5){
                caseSelectionInfo.setCountVotes(5);
            }else if(TongJiInfo!=null){
                caseSelectionInfo.setCountVotes(1);
            }else{
                caseSelectionInfo.setCountVotes(0);
            }
        } catch (Exception e) {
            e.printStackTrace();
            caseSelectionInfo.setCountVotes(0);
            model.addAttribute("caseSelectionInfo", caseSelectionInfo);
            return PREFIX + "/case_enterDetails.html";
        }
        model.addAttribute("caseSelectionInfo", caseSelectionInfo);
        return PREFIX + "/case_enterDetails.html";
    }

    @RequestMapping(value = "/castVote", method = RequestMethod.POST)
    @ResponseBody
    public int castVote(String id,HttpServletRequest request) {
        String ip = request.getRemoteAddr();
        String ua = request.getHeader("User-Agent").toLowerCase();
        try {
            String sql="select id from case_wechat_vote where createtime=left(now(),10) and unique_identification='"+ua+"' ";
            String sql1="select id from case_wechat_vote where createtime=left(now(),10) and unique_identification='"+ua+"' and caseid="+id+" limit 1";
            List<TongJiInfo> TongJiInfoList=sqlMapper.selectList(sql,TongJiInfo.class);
            TongJiInfo TongJiInfo=sqlMapper.selectOne(sql1,TongJiInfo.class);
            if(TongJiInfoList.size()>=5){
                return 5;
            }else if(TongJiInfo!=null){
                return 1;
            }else{
                String insesql="insert into case_wechat_vote (`ip`,`unique_identification`, `caseid`, `createtime`) VALUES " +
                        " ('"+ip+"', '"+ua+"', "+id+",'"+ DateTimeKit.now()+"');";
                sqlMapper.insert(insesql);
                String upsql="update case_selection_information a set votes=votes+1 where id='"+id+"'";
                sqlMapper.update(upsql);
                return 0;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return 2;
        }
    }

    /**
     * 点击登录执行的动作
     */
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public String loginVali(HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        ShiroKit.setSessionAttr("tips", "");
        String username = super.getPara("username").trim();
        String password = super.getPara("password").trim();
        String outpatientName = super.getPara("outpatientName").trim();
        Subject currentUser = ShiroKit.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken(username, password.toCharArray());
        token.setRememberMe(true);
        currentUser.login(token);
        ShiroUser shiroUser = ShiroKit.getUser();
        super.getSession().setAttribute("shiroUser", shiroUser);
        super.getSession().setAttribute("username", shiroUser.getAccount());
        LogManager.me().executeLog(LogTaskFactory.loginLog(shiroUser.getId(), HttpKit.getIp()));
        ShiroKit.getSession().setAttribute("sessionFlag", true);
        ShiroKit.setSessionAttr("outpatientName", outpatientName);
        ShiroKit.setSessionAttr("username", username);
        ShiroKit.setSessionAttr("password", password);
        return REDIRECT + "/caseSelectionVote/";
    }
}